package com.xl.generator.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xl.generator.common.ActionResult;
import com.xl.generator.common.ActionResultService;
import com.xl.generator.domain.CommonUser;
import com.xl.generator.service.CommonUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 〈〉<br>
 *
 * @author lvln5
 * @Description
 * @date 2022/11/16 21:38
 */
@Api(value = "普通用户的增删改查")
@RestController
@RequestMapping("commonUser")
public class CommonUserController {
	@Resource
	private CommonUserService commonUserService;

	@ApiOperation(value = "用户总积分排名接口", notes="新增一个用户接口，根据总积分排名的接口 commonUser 整个实体可不传")
	@PostMapping("ranking")
	public ActionResult test(@RequestBody CommonUser commonUser, @RequestParam("current") Integer current,@RequestParam("Size") Integer size){
		IPage<CommonUser> choiceQuestion = new Page<>();
		choiceQuestion.setCurrent(current);
		choiceQuestion.setSize(size);
		LambdaQueryWrapper<CommonUser> wrapper = new LambdaQueryWrapper<>();
		LambdaQueryWrapper<CommonUser> lambdaQueryWrapper = wrapper.orderByDesc(CommonUser::getTotalCredit);
		IPage<CommonUser> page = commonUserService.page(choiceQuestion, lambdaQueryWrapper);
		return ActionResultService.callBackResultOK(page);
	}
	@ApiOperation(value = "用户总积分排名接口", notes="新增一个用户接口，根据总积分排名的接口 commonUser 整个实体可不传")
	@PostMapping("getSelfRank")
	public ActionResult getSelfRank(@RequestBody CommonUser commonUser){
		Integer rank = commonUserService.getRankByUserId(commonUser.getId());
		return ActionResultService.callBackResultOK(rank);
	}
}
